package com.jyskebank.android.toggl.domain;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import org.json.JSONException;
import org.json.JSONObject;

public class TimeEntry implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -7642147496147766584L;

	/**
	 * 
	 */

	int duration;

	Project project;

	String tagNames;

	private String updatedAt;

	private String workspaceName;

	private long workspaceId;

	private String description;

	private String startTime;

	private String ignoreStartAndStop;

	private String stopTime;

	private boolean billabe;

	private long id;

	public int getDuration() {
		return duration;
	}

	public void setDuration(int duration) {
		this.duration = duration;
	}

	public Project getProject() {
		return project;
	}

	public void setProject(Project project) {
		this.project = project;
	}

	public String getTagNames() {
		return tagNames;
	}

	public void setTagNames(String tagNames) {
		this.tagNames = tagNames;
	}

	public String getUpdatedAt() {
		return updatedAt;
	}

	public void setUpdatedAt(String updatedAt) {
		this.updatedAt = updatedAt;
	}

	public String getWorkspaceName() {
		return workspaceName;
	}

	public void setWorkspaceName(String workspaceName) {
		this.workspaceName = workspaceName;
	}

	public long getWorkspaceId() {
		return workspaceId;
	}

	public void setWorkspaceId(long workspaceId) {
		this.workspaceId = workspaceId;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getStartTime() {
		return startTime;
	}

	public void setStartTime(String startTime) {
		this.startTime = startTime;
	}

	public String isIgnoreStartAndStop() {
		return ignoreStartAndStop;
	}

	public void setIgnoreStartAndStop(String ignoreStartAndStop) {
		this.ignoreStartAndStop = ignoreStartAndStop;
	}

	public String getStopTime() {
		return stopTime;
	}

	public void setStopTime(String stopTime) {
		this.stopTime = stopTime;
	}

	public boolean isBillabe() {
		return billabe;
	}

	public void setBillabe(boolean billabe) {
		this.billabe = billabe;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	@Override
	public String toString() {
		return "TimeEntry [duration=" + duration + ", project=" + project
				+ ", tagNames=" + tagNames + ", updatedAt=" + updatedAt
				+ ", workspaceName=" + workspaceName + ", workspaceId="
				+ workspaceId + ", description=" + description + ", startTime="
				+ startTime + ", ignoreStartAndStop=" + ignoreStartAndStop
				+ ", stopTime=" + stopTime + ", billabe=" + billabe + ", id="
				+ id + "]";
	}

	public String toJSONArray(){
	   StringBuffer sb = new StringBuffer();
	   sb.append("{\"time_entry\":{");
	   sb.append("\"tag_names\":[");
	   if(this.tagNames != null){
		   sb.append("\"" + this.tagNames + "\"]");
	   }else{
		   sb.append("]");
	   }
	   sb.append(",");
	   sb.append("\"billable\":" + this.billabe);
	   sb.append(",");
	   sb.append("\"workspace\":{\"id\":" + this.workspaceId+ "}");
	   sb.append(",");
	   sb.append("\"description\":\"" + this.description + "\"");
	   sb.append(",");
	   sb.append("\"project\":{\"id\":" + this.project.getId()+ "}");
	   sb.append(",");
	   sb.append("\"duration\":" + this.duration);
	   sb.append(",");
	   sb.append("\"start\":\"" + this.startTime + "\"");
	   sb.append(",");
	   sb.append("\"stop\":\"" + this.stopTime + "\"");
	   sb.append(",");
	   sb.append("\"created_with\":\"" + "JBToggl" + "\"");
	   sb.append("}}");
	   System.out.println("toJSONArray " + sb.toString());
	   return sb.toString();
	}
}
